package com.lanou3g.musicenjoy.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.lanou3g.musicenjoy.R;
import com.lanou3g.musicenjoy.adapter.SpecialRecycleAdapter;
import com.lanou3g.musicenjoy.entity.Special;

import com.lanou3g.musicenjoy.adapter.SpecialAdapter;
import com.lanou3g.musicenjoy.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 15/10/20.
 */
public class SpecialFragment extends Fragment  {
    private List<Special.AlbumlistEntity> datas;
    private RequestQueue requestQueue;
    private RecyclerView specialListView;
    private RecyclerView.Adapter adapter;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_special,null);
        requestQueue= VolleySingleton.getInstance(getActivity()).getRequestQueue();
        specialListView= (RecyclerView) view.findViewById(R.id.specialListView);
        specialListView.setLayoutManager(null);
        LinearLayoutManager manager = new LinearLayoutManager(getActivity());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        specialListView.setLayoutManager(manager);
        Bundle bundle=getArguments();
        String a=bundle.getString("aa");
        String url="http://tingapi.ting.baidu.com/v1/restserver/ting?from=android&version=5.6.5.0&" +
                "method=baidu.ting.artist.getAlbumList&format=json&order=1&tinguid="+a+"&offset=0&limits=30";
        Log.i("djfkajfl",url+"");
        StringRequest request=new StringRequest(url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                if (response!=null){
                    Gson gson=new Gson();
                    Special result=gson.fromJson(response,Special.class);
                    if (result!=null){
                        datas=result.getAlbumlist();
                        adapter=new SpecialRecycleAdapter(getActivity(),datas);
                        specialListView.setAdapter(adapter);

                    }
                }

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        requestQueue.add(request);
        return view;
    }

}
